@extends('public.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .ip-purchase-th {
            text-align: center;
        }

        .ip-purchase-td {
            text-align: center;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/ip.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section id="list" class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #009aff;">
                        <div class="box-body" style="">
                            <div class="row">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 1%">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #009aff">
                                        </i></a>
                                    <a href="#"><span
                                                style="font-size: 20px;float: left;color: #009aff">&nbsp;IP交易购买</span></a>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12 col-lg-offset-6 col-md-offset-4 btn-div">
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-addIpPurchase"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">增加购买
                                    </button>
                                    {{--<form action="{{url('user/ip/IpPurchaseSearch')}}" method="post" enctype="multipart/form-data" class="search">--}}
                                        {{--{{csrf_field()}}--}}
                                        {{--<button class="fa fa-search fa-lg"></button>--}}
                                        {{--<input type="search" class="search" value="{{$keywords}}"  id="search-input" name="search">--}}
                                    {{--</form>--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row" style="margin-top: 2%">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="ip-purchase-th">序号</th>
                                <th class="ip-purchase-th">类型</th>
                                <th class="ip-purchase-th">类别</th>
                                <th class="ip-purchase-th">名称</th>
                                <th class="ip-purchase-th">是否可加价购买</th>
                                <th class="ip-purchase-th">补充备注</th>
                                <th class="ip-purchase-th">最低出价</th>
                                <th class="ip-purchase-th">发布日期</th>
                                <th class="ip-purchase-th">进度</th>
                                <th class="ip-purchase-th">操作</th>
                            </tr>
                            </thead>
                            <tbody class="list">
                            @if($product->isEmpty())
                                <tr>
                                    <td class="ip-purchase-th" colspan="10"><h3 align="center">暂无数据</h3></td>
                                </tr>
                            @else
                                @foreach($product as $k =>$v)
                                    <tr>
                                        <td class="ip-purchase-td" style="vertical-align: middle">{{$k+1}}</td>
                                        <td class="ip-purchase-td firstType"
                                            style="vertical-align: middle">{{$v['FirstType']['name']}}</td>
                                        <td class="ip-purchase-td secondType"
                                            style="vertical-align: middle">{{$v['SecondType']['name']}}</td>
                                        <td class="ip-purchase-td name"
                                            style="vertical-align: middle">{{$v['name']}}</td>
                                        <td class="ip-purchase-td need_markup" style="vertical-align: middle">
                                            @if($v['need_markup']==1)
                                                可以
                                            @else
                                                不可以
                                            @endif
                                        </td>
                                        <td class="ip-purchase-td ps" style="vertical-align: middle">
                                            @if(empty($v['ps']))
                                                暂无数据
                                            @else
                                                {{$v['ps']}}
                                            @endif
                                        </td>
                                        <td class="ip-purchase-td min_price" style="vertical-align: middle">
                                            ¥{{$v['min_price']}}</td>
                                        <td class="ip-purchase-td created_at"
                                            style="vertical-align: middle">{{date("Y-m-d",strtotime($v['created_at']))}}</td>
                                        <td class="ip-purchase-td buyIP_progress"
                                            style="vertical-align: middle">{{config('config.buyIP_progress')[$v['progress']-1]}}</td>
                                        <td class="ip-purchase-td" style="vertical-align: middle">
                                            <a href="#" data-toggle="modal" class="p"
                                               ip_id="{{$v['id']}}"
                                               first_id="{{$v['first_type']}}"
                                               second_id="{{$v['second_type']}}"
                                               name="{{$v['name']}}"
                                               need_markup="{{$v['need_markup']}}"
                                               ps="{{$v['ps']}}"
                                               min_price="{{$v['min_price']}}"
                                               progress_id="{{$v['progress']}}"
                                               data-target="#edit-IP-purchaseModal">修改&nbsp;</a>
                                            <a href="{{url('user/ip/delIpPay',['id'=>$v['id']])}}"
                                               onclick="return confirm('确定要删除吗?')">&nbsp;删除</a>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public.addIpPurchaseModal')
    @include('public.editIPPurchaseModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/bootstrap-datetimepicker.min.js')}}"></script>
    <script src="{{asset('js/ip.js')}}"></script>
    <script src="{{asset('js/list.min.js')}}"></script>
    <script>
        var options = {
            valueNames: ['firstType','secondType','name','need_markup','ps','min_price','created_at','buyIP_progress']
        };
        var List = new List('list', options);
        List.search($('#search-input').val());
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });

        function getType(e) {
            $.ajax({
                url: '{{url('user/ip/getSecondType')}}',
                type: 'post',
                dataType: 'json',
                data: {
                    'id': e.val()
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    var type = $('#second');
                    type.empty();
                    var size = data.length;
                    if (size <= 0) {
                        type.append('<option value="-1">类别</option>');
                    } else {
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            type.append('<option value="' + item['id'] + '">' + item['name'] + '</option>');
                        }
                    }
                }
            })
        }

        function editGetType(e) {
            $.ajax({
                url: '{{url('user/ip/getSecondType')}}',
                type: 'post',
                dataType: 'json',
                data: {
                    'id': e.val()
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    var type = $('#edit_second_type');
                    type.empty();
                    var size = data.length;
                    if (size <= 0) {
                        type.append('<option value="-1">类别</option>');
                    } else {
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            type.append('<option value="' + item['id'] + '">' + item['name'] + '</option>');
                        }
                    }
                }
            })
        }

        $(".p").click(function () {
            var first_id = $(this).attr('first_id');
            getSecondDate(first_id);
            var second_id = $(this).attr('second_id');
            var need_markup = $(this).attr('need_markup');
            var progress_id = $(this).attr('progress_id');
//            console.log(first_id,progress_id,second_id,need_markup);
            $("#hide_id").val($(this).attr('ip_id'));
            $("#edit_name").val($(this).attr('name'));
            $("#edit_supplement").val($(this).attr('ps'));
            $("#edit_lowest_price").val($(this).attr('min_price'));
            $("#edit_first_type").find("option[value='" + first_id + "']").attr("selected", true);
            $("#edit_second_type").find("option[value='" + second_id + "']").attr("selected", true);
            $("#edit_is_authorize").find("option[value='" + need_markup + "']").attr("selected", true);
            $("#edit_progress").find("option[value='" + progress_id + "']").attr("selected", true);
        });

        function getSecondDate(first_id) {
            console.log(first_id);
            $.ajax({
                url: '{{url('user/ip/getSecondDate')}}',
                type: 'post',
                dataType: 'json',
                data: {
                    'id': first_id
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    var type = $('#edit_second_type');
                    type.empty();
                    var size = data.length;
                    if (size <= 0) {
                        type.append('<option value="-1">类别</option>');
                    } else {
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            type.append('<option value="' + item['id'] + '">' + item['name'] + '</option>');
                        }
                    }
                }
            })
        }
    </script>
@stop
